unit Afficher;

interface

uses ExtCtrls, sysutils, graphics, dialogs;
type TabloCarre = Array[1..15,1..15] OF Byte;
     TabloLettre = Array[0..16,0..16] OF Char;

Procedure AfficherCarre(Image1 : Timage);
Function ValeurCarreF : tabloCarre;
Function ValeurMotF(Chaine : String; Hor : Boolean;X,Y,Size:byte) : byte;
Function ValeurMotFSimul(Chaine : String; Hor : Boolean;X,Y,Size:byte) : byte;

Var Tab : TabloCarre;
Var Plateau : TabloLettre;
Const ValeurLettre : array[1..26] OF byte = (1,3,3,2,1,4,2,4,1,8,10,1,2,1,1,3,8,1,1,1,1,4,10,10,10,10);

implementation


Procedure AfficherCarre(Image1 : Timage);
var i, j : byte;
Begin
  Image1.Canvas.Brush.Color := $00E1E3E3;
  Image1.Canvas.Pen.Color := ClCream;
  Image1.Canvas.Pen.Width := 2;

  For I := 1 to 15 do   //créee les carré gris
    For J := 1 to 15 do
      Image1.canvas.Rectangle(Image1.Width div 15 *(j-1)+1,Image1.Height div 15 * i,Image1.Width div 15 * j, Image1.Height div 15 *(i-1)+ 1);

  Image1.Canvas.Font.Size := 20;
  Image1.Canvas.Brush.Color := $008080FF;
  Image1.Canvas.Rectangle(Image1.Width div 15 * 7 + 1,Image1.Height div 15 * 7  + 1, Image1.Width div 15 * 8, Image1.Height div 15 * 8);

  Image1.Canvas.Brush.Color := ClRed; //crée les : mots compte triple.
  Image1.Canvas.Rectangle(1,Image1.Height div 15,Image1.Width div 15 - 1, 1);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 7 + 1,Image1.Height div 15,Image1.Width div 15 * 8 - 1, 1);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 14 + 1,Image1.Height div 15,Image1.Width - 1, 1);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 14 + 1,Image1.Height div 15 * 8,Image1.Width - 1, Image1.Height div 15 * 7 + 1);
  Image1.Canvas.Rectangle(1,Image1.Height - 1,Image1.Width div 15 , Image1.Width div 15 * 14 + 1);
  Image1.Canvas.Rectangle(1 ,Image1.height - 1,Image1.Width div 15 , Image1.Height div 15 * 14 + 1);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 14 + 1 ,Image1.Height - 1 ,Image1.Width - 1, Image1.Height div 15 * 14 + 1);
  Image1.Canvas.Rectangle(1,Image1.Height div 15 * 8 + 1,Image1.Width div 15 - 1 , Image1.Height div 15 * 7 + 1);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 7 + 1,Image1.Height - 1,Image1.Width div 15 * 8, Image1.Height div 15 * 14 + 1);

     //crée les cases : mot compte double
  For I := 1 To 4 Do
    Begin
      Image1.Canvas.Brush.Color := $008080FF;
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i + 9) + 1,Image1.Height div 15 * (i + 9 + 1), Image1.Width div 15 * (i + 9 + 1), Image1.Height div 15 * (i + 9) + 1);
      Image1.Canvas.Rectangle(Image1.Width div 15 * i + 1,Image1.Height div 15 * (i + 1), Image1.Width div 15 * (i + 1), Image1.Height div 15 * i + 1);
      Image1.Canvas.Rectangle(Image1.Width div 15 * (5 - i) + 1,Image1.Height div 15 * (i + 1 + 9), Image1.Width div 15 * ( 5 - i + 1), Image1.Height div 15 * (i + 9) + 1);
      Image1.Canvas.Rectangle(Image1.Width div 15 * (9 + i) + 1,Image1.Height div 15 * (6 - i), Image1.Width div 15 * ( i + 9 + 1), Image1.Height div 15 * (5 - i) + 1);
      Image1.Canvas.Brush.Color := ClBlue; //crée les case lettre compte triple
      Image1.Canvas.Rectangle(Image1.Width div 15 * (1 + (i - 1) * 4), Image1.Height div 15 * 5, Image1.Width div 15 * (2 + (i - 1) * 4), Image1.Height div 15 * 6);
      Image1.Canvas.Rectangle(Image1.Width div 15 * (1 + (i - 1) * 4), Image1.Height div 15 * 9, Image1.Width div 15 * (2 + (i - 1) * 4), Image1.Height div 15 * 10);
    End;

  Image1.Canvas.Rectangle(Image1.Width div 15 * 5, Image1.Height div 15, Image1.Width div 15 * 6, Image1.Height div 15 * 2);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 9, Image1.Height div 15, Image1.Width div 15 * 10, Image1.Height div 15 * 2);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 5, Image1.Height div 15 * 14, Image1.Width div 15 * 6, Image1.Height div 15 * 13);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 9, Image1.Height div 15 * 14, Image1.Width div 15 * 10, Image1.Height div 15 * 13);

  Image1.Canvas.Brush.Color := ClAqua;

  For I := 0 To 1 Do
    Begin
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 8 + 3),Image1.Height div 15 ,Image1.Width div 15 * (i * 8 + 4),1 );
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 2 + 6),Image1.Height div 15 * 2 ,Image1.Width div 15 * (i * 2 + 7),Image1.Height div 15 * 3 );
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 8 + 3),Image1.Height - 1 ,Image1.Width div 15 * (i * 8 + 4), Image1.Height div 15 * 14 );
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 2 + 6),Image1.Height div 15 * 12 ,Image1.Width div 15 * (i * 2 + 7),Image1.Height div 15 * 13 );
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 8 + 3),Image1.Height div 15 * 8 ,Image1.Width div 15 * (i * 8 + 4), Image1.Height div 15 * 7 );
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 4 + 2), Image1.Height div 15 * 7, Image1.Width div 15 * (i * 4 + 3), Image1.Height div 15 * 6);
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 4 + 2), Image1.Height div 15 * 9, Image1.Width div 15 * (i * 4 + 3), Image1.Height div 15 * 8);
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 4 + 8), Image1.Height div 15 * 7, Image1.Width div 15 * (i * 4 + 9), Image1.Height div 15 * 6);
      Image1.Canvas.Rectangle(Image1.Width div 15 * (i * 4 + 8), Image1.Height div 15 * 9, Image1.Width div 15 * (i * 4 + 9), Image1.Height div 15 * 8);
    End;

  Image1.Canvas.Rectangle(1,Image1.Height div 15 * 3, Image1.Width div 15, Image1.Height div 15 * 4);
  Image1.Canvas.Rectangle(1,Image1.Height div 15 * 11, Image1.Width div 15, Image1.Height div 15 * 12);

  Image1.Canvas.Rectangle(Image1.Width div 15 * 7,Image1.Height div 15 * 3, Image1.Width div 15 * 8, Image1.Height div 15 * 4);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 7,Image1.Height div 15 * 11, Image1.Width div 15 * 8, Image1.Height div 15 * 12);

  Image1.Canvas.Rectangle(Image1.Width div 15 * 14,Image1.Height div 15 * 3, Image1.Width - 1, Image1.Height div 15 * 4);
  Image1.Canvas.Rectangle(Image1.Width div 15 * 14,Image1.Height div 15 * 11, Image1.Width - 1, Image1.Height div 15 * 12);


end;

Function ValeurCarreF : tabloCarre;
Var i,j : byte;
Begin
  For I := 1 to 15 Do
    For J := 1 to 15 Do
      Result[i,j] := 0;

  Result[1,1] := 3;
  Result[8,1] := 3;
  Result[15,1] := 3;
  Result[1,8] := 3;
  Result[1,15] := 3;
  Result[8,15] := 3;
  Result[15,15] := 3;
  Result[15,8] := 3;

  Result[2,2] := 2;
  Result[3,3] := 2;
  Result[4,4] := 2;
  Result[5,5] := 2;
  Result[14,2] := 2;
  Result[13,3] := 2;
  Result[12,4] := 2;
  Result[11,5] := 2;
  Result[8,8] := 2;

  Result[2,14] := 2;
  Result[3,13] := 2;
  Result[4,12] := 2;
  Result[5,11] := 2;
  Result[14,14] := 2;
  Result[13,13] := 2;
  Result[12,12] := 2;
  Result[11,11] := 2;

  Result[4,1] := 4;
  Result[12,1] := 4;
  Result[7,3] := 4;
  Result[9,3] := 4;
  Result[1,4] := 4;
  Result[8,4] := 4;
  Result[15,4] := 4;
  Result[3,7] := 4;
  Result[7,7] := 4;
  Result[9,7] := 4;
  Result[13,7] := 4;
  Result[4,8] := 4;
  Result[12,8] := 4;
  Result[4,15] := 4;
  Result[12,15] := 4;
  Result[7,13] := 4;
  Result[9,13] := 4;
  Result[1,12] := 4;
  Result[8,12] := 4;
  Result[15,12] := 4;
  Result[3,9] := 4;
  Result[7,9] := 4;
  Result[9,9] := 4;
  Result[13,9] := 4;

  Result[6,2] := 5;
  Result[10,2] := 5;
  Result[6,14] := 5;
  Result[10,14] := 5;
  Result[2,6] := 5;
  Result[6,6] := 5;
  Result[10,6] := 5;
  Result[14,6] := 5;

  Result[2,10] := 5;
  Result[6,10] := 5;
  Result[10,10] := 5;
  Result[14,10] := 5;
End;

Function ValeurMotF(Chaine : String; Hor : Boolean;X,Y,Size:byte) : byte;
Var I, J,Z, ValeurLettreCur, ValeurMotCur1, ValeurMotCur: byte;
    ResultatTab : Array Of Byte;
Begin
ValeurMotCur := 1;
Result := 0;
SetLength(ResultatTab, size + 1);
IF Hor = True Then
  For I := 1 To Size Do
    Begin
      ResultatTab[I] := 0;
      ValeurLettreCur := 1;
      ValeurMotCur1 := 1;
      Case Tab[X + I - 1,Y] OF
        2 : Begin
            ValeurMotCur := ValeurMotCur * 2;
            ValeurMotCur1 := 2;
            End;
        3 : Begin
            ValeurMotCur := ValeurMotCur * 3;
            ValeurMotCur1 := 3;
            End;
        4 : ValeurLettreCur := ValeurLettreCur * 2;
        5 : ValeurLettreCur := ValeurLettreCur * 3;
      End;
      IF Plateau[X + I - 1, Y] = '' Then
        Begin
          J := 1;
          While Plateau[X + i - 1, Y + J] <> '' Do
            Begin
              ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Plateau[X + I - 1, Y + J]) - 64]);
              Inc(j);
            End;
          Z := 1;
          While Plateau[X + I - 1, Y - Z] <> '' Do
            Begin
              ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Plateau[X + I - 1, Y - Z]) - 64]);
              Inc(Z)
            End;
          IF Z + J - 2 <> 0 Then
            Begin
              ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Chaine[i]) - 64] * ValeurLettreCur);
              ResultatTab[I] := ResultatTab[I] * ValeurMotCur1;
            End;
        End;

      Tab[X + I - 1,Y] := 1;
      Result := Result + (ValeurLettre[Ord(Chaine[i]) - 64] * ValeurLettreCur);
    End
Else
  For I := 1 To Size Do
    Begin
      ValeurMotCur1 := 1;
      ResultatTab[I] := 0;
      ValeurLettreCur := 1;
      Case Tab[X,Y + I - 1] OF
        2 : Begin
              ValeurMotCur := ValeurMotCur * 2;
              ValeurMotCur1 := 2;
            End;
        3 : Begin
              ValeurMotCur := ValeurMotCur * 3;
              ValeurMotCur1 := 3;
            End;
        4 : ValeurLettreCur := ValeurLettreCur * 2;
        5 : ValeurLettreCur := ValeurLettreCur * 3;
      End;

     IF Plateau[X, Y + I - 1] = '' Then
       Begin
         J := 1;
         While Plateau[X + J, Y + I - 1] <> '' Do
           Begin
             ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Plateau[X + J, Y + I - 1]) - 64]);
             Inc(j);
           End;
         Z := 1;
         While Plateau[X - Z, Y + I - 1] <> '' Do
           Begin
             ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Plateau[X - Z, Y + I - 1]) - 64]);
             Inc(Z)
           End;
         IF Z + J - 2 <> 0 Then
           Begin
             ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Chaine[i]) - 64] * ValeurLettreCur);
             ResultatTab[I] := ResultatTab[I] * ValeurMotCur1;
           End;
       End;
      Tab[X,Y + I - 1] := 1;
      Result := Result + (ValeurLettre[Ord(Chaine[i]) - 64] * ValeurLettreCur);
    End;


Result := Result * ValeurMotCur;

For I := 0 TO High(ResultatTab) Do
  Result := Result + ResultatTab[I];

End;






Function ValeurMotFSimul(Chaine : String; Hor : Boolean;X,Y,Size:byte) : byte;
Var I, J,Z, ValeurLettreCur, ValeurMotCur1, ValeurMotCur: byte;
    ResultatTab : Array Of Byte;
Begin
ValeurMotCur := 1;
Result := 0;
SetLength(ResultatTab, size + 1);
Chaine := Chaine;
IF Hor = True Then
  For I := 1 To Size Do
    Begin
      ResultatTab[I] := 0;
      ValeurLettreCur := 1;
      ValeurMotCur1 := 1;
      Case Tab[X + I - 1,Y] OF
        2 : Begin
            ValeurMotCur := ValeurMotCur * 2;
            ValeurMotCur1 := 2;
            End;
        3 : Begin
            ValeurMotCur := ValeurMotCur * 3;
            ValeurMotCur1 := 3;
            End;
        4 : ValeurLettreCur := ValeurLettreCur * 2;
        5 : ValeurLettreCur := ValeurLettreCur * 3;
      End;
      IF Plateau[X + I - 1, Y] = '' Then
        Begin
          J := 1;
          While Plateau[X + i - 1, Y + J] <> '' Do
            Begin
              ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Plateau[X + I - 1, Y + J]) - 96]);
              Inc(j);
            End;
          Z := 1;
          While Plateau[X + I - 1, Y - Z] <> '' Do
            Begin
              ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Plateau[X + I - 1, Y - Z]) - 96]);
              Inc(Z)
            End;
          IF Z + J - 2 <> 0 Then
            Begin
              ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Chaine[i]) - 96] * ValeurLettreCur);
              ResultatTab[I] := ResultatTab[I] * ValeurMotCur1;
            End;
        End;

      Result := Result + (ValeurLettre[Ord(Chaine[i]) - 96] * ValeurLettreCur);

    End
Else
  For I := 1 To Size Do
    Begin
      ValeurMotCur1 := 1;
      ResultatTab[I] := 0;
      ValeurLettreCur := 1;
      Case Tab[X,Y + I - 1] OF
        2 : Begin
              ValeurMotCur := ValeurMotCur * 2;
              ValeurMotCur1 := 2;
            End;
        3 : Begin
              ValeurMotCur := ValeurMotCur * 3;
              ValeurMotCur1 := 3;
            End;
        4 : ValeurLettreCur := ValeurLettreCur * 2;
        5 : ValeurLettreCur := ValeurLettreCur * 3;
      End;

     IF Plateau[X, Y + I - 1] = '' Then
       Begin
         J := 1;
         While Plateau[X + J, Y + I - 1] <> '' Do
           Begin
             ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Plateau[X + J, Y + I - 1]) - 96]);
             Inc(j);
           End;
         Z := 1;
         While Plateau[X - Z, Y + I - 1] <> '' Do
           Begin
             ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Plateau[X - Z, Y + I - 1]) - 96]);
             Inc(Z)
           End;
         IF Z + J - 2 <> 0 Then
           Begin
             ResultatTab[I] := ResultatTab[I] + (ValeurLettre[Ord(Chaine[i]) - 96] * ValeurLettreCur);
             ResultatTab[I] := ResultatTab[I] * ValeurMotCur1;
           End;
       End;
      Result := Result + (ValeurLettre[Ord(Chaine[i]) - 96] * ValeurLettreCur);
    End;


Result := Result * ValeurMotCur;

For I := 0 TO High(ResultatTab) Do                
  Result := Result + ResultatTab[I];


End;


end.
